package com.cskaoyan._03api;

import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/21 15:54
 **/

public class SleepDemo {
    public static void main(String[] args) {
        System.out.println("main start");
        // 创建线程对象
        SleepThread t = new SleepThread();


        // start启动
        t.start();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main end");

    }
}

class SleepThread extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+
                    "----"+i);

            // sleep(毫秒)
            // 暂停执行
            try {
                Thread.sleep(1000);
                // 等价
                //TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}